/*
package com.atguigu.flink.chapter11;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.descriptors.Csv;
import org.apache.flink.table.descriptors.Json;
import org.apache.flink.table.descriptors.Kafka;
import org.apache.flink.table.descriptors.Schema;

import static org.apache.flink.table.api.Expressions.$;

*/
/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/9/24 10:10
 *//*

public class Flink04_Table_kafka {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 20000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(2);
        
        StreamTableEnvironment tenv = StreamTableEnvironment.create(env);
        
        Schema schema = new Schema()
            .field("id", DataTypes.STRING())
            .field("ts", DataTypes.BIGINT())
            .field("vc", DataTypes.INT());
        
        // 建立动态表与kafka的 source topic进行关联
        tenv
            .connect(
                new Kafka()
                    .version("universal")
                    .property("bootstrap.servers", "hadoop162:9092")
                    .property("group.id", "Flink04_Table_kafka")
                    .topic("s1")
                    .startFromLatest()
            )
            .withFormat(new Csv())
            .withSchema(schema)
            .createTemporaryTable("s1");
        
        Table table = tenv.from("s1");
        Table result = table.select($("id"), $("ts"), $("vc"));
        
        // 建立动态表与kafka的 sink topic进行关联
        tenv
            .connect(
                new Kafka()
                    .version("universal")
                    .property("bootstrap.servers", "hadoop162:9092")
                    .topic("s2")
                    .sinkPartitionerRoundRobin()
            )
            .withFormat(new Json())  // json格式不支持文件
            .withSchema(schema)
            .createTemporaryTable("s2");
        
        // 把结果写入到sink表
        result.executeInsert("s2");
        
    }
}
*/
